﻿#region Usings

using System;
using System.Collections.Generic;
using System.Linq;

#endregion

namespace KanbanBoard.Server.Command.DomainModel {
    public class Lane {
        private readonly ICollection<Task> tasks = new List<Task>();

        internal void MoveFrom(Task task, Lane lane) {
            lane.tasks.Remove(task);

            var lowestPriorityTask = tasks.LastOrDefault();
            if (lowestPriorityTask != null) {
                task.Prioritize().Below(lowestPriorityTask);
            } else {
                task.Prioritize().StartNewPriorityChain();
            }

            tasks.Add(task);
        }

        internal static readonly Lane Null = new Lane();
    }
}